package com.example.secondhandshop.ui.activity;

import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.Fragment;

import com.example.secondhandshop.R;
import com.example.secondhandshop.ui.fragment.HomeFragment;
//import com.example.secondhandshop.ui.fragment.MessageFragment;
import com.example.secondhandshop.ui.fragment.MessageFragment;
import com.example.secondhandshop.ui.fragment.PersonFragment;
import com.google.android.material.bottomnavigation.BottomNavigationView;

public class MainActivity extends AppCompatActivity {

    private BottomNavigationView bottomNavigationView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        // 初始化 BottomNavigationView
        bottomNavigationView = findViewById(R.id.bottom_nav_menu);

        // 设置监听器
        bottomNavigationView.setOnItemSelectedListener(item -> {
            Fragment selectedFragment = null;

            if (item.getItemId() == R.id.navigation_home) {
                selectedFragment = new HomeFragment();
            } else if (item.getItemId() == R.id.navigation_message){
                selectedFragment = new MessageFragment();
            } else if(item.getItemId() == R.id.navigation_personal){
                selectedFragment = new PersonFragment();
            }
            return replaceFragment(selectedFragment);
        });
    }


    private boolean replaceFragment(Fragment fragment) {
        if (fragment != null) {
            getSupportFragmentManager()
                    .beginTransaction()
                    .replace(R.id.fragment_container_view, fragment)
                    .commit();
            return true;
        }
        return false;
    }
}